package com.zm.core.controller;

import java.util.List;

import com.jfinal.plugin.activerecord.Page;
import com.zm.core.common.controller.BaseController;
import com.zm.core.model.Size;

public class SizeController extends BaseController {


	public void index()
	{
		render("manage/size.html");
	}
	public void getPage()
	{
		Page<Size> page = Size.dao.paginate(getParaToInt("page"), getParaToInt("rows"), "select d_logo.name as logo,d_size.* ", " from d_size left join d_logo on d_size.logo_id=d_logo.id");
		setAttr("rows", page.getList());
		setAttr("total", page.getTotalRow());
		renderJson();
	}
	public void getById()
	{
		Size size = Size.dao.findById(getPara("id"));
		renderJson(size);
	}
	public void delete()
	{
		Size.dao.deleteById(getPara("id"));
		this.setAttr("title", "提示");
		this.setAttr("message", "删除成功");
		renderJson();
	}
	public void submit()
	{
		Size size = getModel(Size.class);
		if(size.get("id")!=null)
		{
			Size alreadysize=Size.dao.findFirst(" SELECT id FROM d_size WHERE id= '"+size.get("id").toString()+"' ");
			if(null!=alreadysize)
			{
				size.update();
				renderHtml("<script type='text/javascript'>alert('尺码保存成功')</script>");
				return;
			}
		}
		
		size.save();
		renderHtml("<script type='text/javascript'>alert('尺码保存成功')</script>");

	}
	
	public void getList()
	{
		List<Size> list = Size.dao.find(" SELECT * FROM d_size ");
		renderJson(list);
	}
	



}
